'use strict';
define(['../main','../routes'],function(module,config){
    module.controller("indexCtrl",function($scope,$rootScope){
        $rootScope.commonUtil={
            addDate:function addDate(dadd,dd){
                var a = dd?new Date(dd):new Date();
                a = a.valueOf();
                a = a + dadd * 24 * 60 * 60 * 1000;
                a = new Date(a);
                var year=a.getFullYear();
                var month=a.getMonth()<9?'0'+(a.getMonth()+1):a.getMonth()+1;
                var date= a.getDate()<10?'0'+ a.getDate(): a.getDate();
                return year+"-"+ month+"-"+ date;
            }
        };
        $rootScope.routes={
            main:[],
            dropdown:[]
        };
        var dropDownTemp={};
        for(var key in config.routes){
            var node=config.routes[key];
            if(node.type=='main'){
                $rootScope.routes.main.push({url:key,title:node.name});
            }
            else if(node.type=='node'){
                var dd=dropDownTemp[node.parent];
                if(dd){
                    dd.nodes.push({url:key,title:node.name});
                }
                else{
                    dropDownTemp[node.parent]={url:node.parent,name:node.parentName,nodes:[{url:key,title:node.name}]}
                }
            }
        }
        for(key in dropDownTemp){
            $rootScope.routes.dropdown.push(dropDownTemp[key]);
        }
        $rootScope.navActive=config.defaultRoutePath;
    });
});
